source ~/.bashrc
source ~/SHELL/isFileEmpty.sh
if  test ! -s "$1" ; then
	echo "This shell clean the directory in a list"
	echo "The only ptr is the file name of a gene list."
	echo "Each line of the list has the following info of one gene:"
	echo "#name   chrom   strand  txStart txEnd, given by the UCSC genome browser." 
	exit
fi
exec < $1
while read line
do
	if [[ $(expr match $1 "#") == 1 ]]; then
		continue   # comment 
	fi
	# echo will turn tab into space automatically
	gene=$(echo $line | cut -f 1 -d' ')
	chr=$(echo $line | cut -f 2 -d' ')
	strand=$(echo $line | cut -f 3 -d' ')
	gStart=$(echo $line | cut -f 4 -d' ')
	gEnd=$(echo $line | cut -f 5 -d' ')
	if [ -d $gene ]; then
		cd $gene
		echo $gene
		if [ $(basename $PWD) == $gene ]; then
			\rm *
			if [ -d ./tmp ]; then
				cd ./tmp
				\rm *
				cd ..
				\rmdir ./tmp
			fi
			cd ..
			\rmdir $gene
		fi 
	fi
done
